package com.binhai.springboot.person.controller;

import com.binhai.springboot.person.bean.PersonBean;
import com.binhai.springboot.person.service.PersonService;
import com.binhai.springboot.user.bean.UserBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/person")
public class PersonController {
    @Autowired
    private PersonService service;

    @RequestMapping("/toMain.do")
    public String toMain(){

        return "user/user";
    }
    @RequestMapping("/toPerson.do")
    public String toPerson(){

        return "person/person";
    }

    @RequestMapping("/getAllData.do")
    @ResponseBody
    public List getAllData(){

        return service.getAllData();
    }


    @RequestMapping("/saveData.do")
    @ResponseBody
    public Map saveData(@RequestBody PersonBean bean){

        return service.saveData(bean);
    }

    @RequestMapping("/updateData.do")
    @ResponseBody
    public Map updateData(@RequestBody PersonBean bean){

        return service.updateData(bean);
    }
    @RequestMapping("/deleteData.do")
    @ResponseBody
    public Map deleteData(@RequestBody PersonBean bean){

        return service.deleteData(bean);
    }


    @RequestMapping("/selectData.do")
    @ResponseBody
    public List selectData(@RequestBody PersonBean bean){

        return service.selectData(bean.getName ());
    }

    @RequestMapping("/person.do")
    public String person(PersonBean bean){
        return service.person2(bean);
    }

    @RequestMapping("/login.do")
    public String login(UserBean bean, String code, PersonBean beanbean){
        return service.login(bean,code,beanbean);
    }
}
